package hot100;

import com.二叉树.练习题.TreeNode;

import java.util.LinkedList;

public class h8_验证二叉搜索树 {
    public boolean isValidBST(TreeNode root) {
        TreeNode p = root;
        LinkedList<TreeNode> queue = new LinkedList<>();
        long pre = Long.MIN_VALUE;
        while (p != null || !queue.isEmpty()) {
            if (p != null) {
                queue.addLast(p);
                p = p.left;
            }else {
                TreeNode pop = queue.pollLast();
                if(pre >= pop.val){
                    return false;
                }
                pre = pop.val;
                p = pop.right;
            }
        }
        return true;
    }
}
